package algorithm.poj.p3000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;


/**
 * 分析：
 * 
 * 实现：
 * 
 * 经验：
 * 
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P3252 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P3252.class.getResource("P3252.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		String line = stdin.readLine();
		String[] tmp = line.trim().split(" ");
		int start = Integer.valueOf(tmp[0]);
		int end = Integer.valueOf(tmp[1]);
		if (start == 1) {
			System.out.println(count(end, 0));
		} else {
			System.out.println(count(end, 0) - count(start-1, 0));
		}
		
//		for (int n = 1; n < 1000000; n ++) {
//			int a = count(n, 0);
//			int b = count2(n, 0);
//			if (a != b) {
//				System.out.println(n + ":" + "a=" + a + ", b=" + b);
//			}
//		}
	}
	
	private static int count(int n, int d) {
		return count(Integer.toBinaryString(n).toCharArray(), d);
	}

	/**
	 * ns[]是一个0-1数组. ns[0]='1'
	 * 返回小于等于ns[]，满足下面条件的数组的个数：
	 * 0的数目 - 1的数目 >= d
	 * @param n
	 * @return
	 */
	private static int count(char[] ns, int d) {
		
		if (ns.length == 0) {
			return 0;
		} else if (ns[0] == '0') {
			throw new RuntimeException("Never Occurs!");
		} else if (ns.length == 1) {	//ns = ['1']
			return (d <= -1)?1:0;
		} else {
			int count = 0;
			
			//count all number whose length less ns.length and start with '1'
			for (int l = 1; l < ns.length; l ++) {
				for (int i = 0; i <= (l-d)/2-1; i ++) {
					count += c(l-1, i);
				}
			}
			
			//iterate here!
			int zeros = 0;
			for (int i = 1; i < ns.length; i ++) {
				if (ns[i] == '0') {
					zeros ++;
				} else {
					break;
				}
			}
			if (ns.length == 1+zeros) {
				if (zeros-1>=d) count ++;
			} else {
				char[] nns = new char[ns.length-1-zeros];
				
				for (int i = 0; i < nns.length; i ++) nns[i] = ns[i+1+zeros];
				count += f(nns, d+1-zeros);
			}
			return count;
		}
	}
	
	/**
	 * 长度和ns一样,但排序在ns之前，满足0-1>=d的字符串个数
	 * 字符串按照长度从少到多，大小从小到大排列
	 * @param ns
	 * @param d
	 * @return
	 */
	private static int f(char[] ns, int d) {
		
		if (ns.length == 0) {
			return 0;
		} else if (ns.length == 1) {
			if (ns[0] == '0') {
				return (d <= 1)?1:0;
			} else {	//ns[0] == '1' 
				if (d <= -1) return 2;
				else if (d <= 1) return 1;
				else return 0;
			}
		} else {
			int count = 0;
			if (ns[0] == '0') {
				int zeros = 0;
				for (int i = 0; i < ns.length; i ++) {
					if (ns[i] == '0') {
						zeros ++;
					} else {
						break;
					}
				}
				if (zeros == ns.length) {
					if (zeros >= d) count ++;
				} else {
					char[] nns = new char[ns.length-zeros];
					
					for (int i = 0; i < nns.length; i ++) nns[i] = ns[i+zeros];
					count += f(nns, d-zeros);
				}
			} else {
				char[] nns = new char[ns.length-1];
				for (int i = 0; i < nns.length; i ++) nns[i] = ns[i+1];
				
				int l = ns.length-1; 
				for (int i = 0; i <= (l-d+1)/2.0; i ++) {
					count += c(l, i);
				}
				count += f(nns, d+1);
			}
//			System.out.println("f(" + new String(ns) + "," + d + ")=" + count);
			return count;
		}
	}
	
//	private static int count2(int n, int d) {
//		
//		int count = 0;
//		for (int m = 1; m <= n; m ++) {
//			char[] cs = Integer.toBinaryString(m).toCharArray();
//			int x = 0;
//			int y = 0;
//			for (int i = 0; i < cs.length; i ++) {
//				if (cs[i] == '0') x ++;
//				else y ++;
//			}
//			if (x - y >= d) count ++;
//		}
//		return count;
//	}
	
	/**
	 * C(m,n)
	 * @param m
	 * @param n
	 * @return
	 */
	private static long c(long m, long n) {
		
		if (m < n) return 0;
		long r = 1;
		for (long i = 0; i < (long)Math.min(m-n, n); i ++) {
			r *= (m-i);
			r /= i+1;
		}
		return r;
	}
}
